<template>
	<view>
		<uni-search-bar v-model="value" :radius="100" @confirm="search" placeholder="搜你想吃的" bgColor="#FFF"></uni-search-bar>
		<view v-if="search_list">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#ff6600"></uni-segmented-control>
			        <view class="content">
			            <view v-show="current === 0">
			                <SearchCard v-for="(item,index) in search_list" :key="index" :item="item.r"/></SearchCard>
			            </view>
			            <view v-show="current === 1">
			                <SearchCard v-for="(item,index) in love_list" :key="index" :item="item.r"/></SearchCard>
			            </view>
			            <view v-show="current === 2">
			                <SearchCard v-for="(item,index) in do_list" :key="index" :item="item.r"/></SearchCard>
			            </view>
			        </view>
		</view>
	</view>
</template>

<script>
	import SearchCard from '@/components/SearchCard/SearchCard.vue'
	export default {
		components: {
			SearchCard
		},
		data() {
			return {
				search_list:null,
				current:0,
				items:["综合最佳","收藏最多","做过最多"],
				value:'',
				love_list:null,
				do_list:null,
			};
		},
		methods:{
			search(e){
				// console.log(e.value);
				this.search_list=null,
				this.love_list=null,
				this.do_list=null,
				this.Load(e);
			},
			Load(e){
				this.value=e.value;
				uni.request({
					url: "https://apis.netstart.cn/douguo/recipe/search",
					data:{
					       keyword: e.value,
					       offset:0,
					       limit:20,
					    },
					success: (res) => {
							this.search_list = res.data.result.list;
					    }
				});
			},
			onClickItem(e){
				console.log(e.currentIndex)
				this.current = e.currentIndex
				if(e.currentIndex == 1){
					uni.request({
						url: "https://apis.netstart.cn/douguo/recipe/search",
						data:{
						       keyword: this.value,
						       offset:0,
						       limit:20,
						       order:2,
						    },
						success: (res) => {
								this.love_list = res.data.result.list;
						    }
					});
				}
				if(e.currentIndex == 2){
					uni.request({
						url: "https://apis.netstart.cn/douguo/recipe/search",
						data:{
						       keyword: this.value,
						       offset:0,
						       limit:20,
						       order:3,
						    },
						success: (res) => {
								this.do_list = res.data.result.list;
						    }
					});
					
				}
				
			}
		},
		onLoad: function (option) {
			this.Load(option);
		},
	}
</script>

<style lang="less">

</style>
